import { defineStore } from 'pinia'
import { ref } from 'vue'


export const useAdminStore = defineStore('admin', () => {
  const adminInfo = ref(null)

  // 设置管理员信息
  const setAdminInfo = (info) => {
    adminInfo.value = info
  }

  // 清除管理员信息
  const clearAdminInfo = () => {
    adminInfo.value = null
  }

  // 检查权限
  const hasPermission = (permission) => {
    console.log("当前管理员的信息是：",adminInfo.value)
    console.log("当前选择的权限是：",permission)
    // console.log("当前管理员是否有权限：",adminInfo.value && adminInfo.value[permission] === true)
    return adminInfo.value && adminInfo.value[permission] === true
  }



  return {
    adminInfo,
    setAdminInfo,
    hasPermission,
    clearAdminInfo
  }
}, {
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'admin-store',
        storage: localStorage
      }
    ]
  }
}) 